<template>
	<view class="wrap">
		<view class="titles">身份证信息</view>
		<view class="imgMain">
			<view class="mainA content"><image src="../../static/new/Examples1.png" /><image class="aaa" src="../../static/new/Examples.png" mode=""></image></view>
			<view class="mainB content"><image @click="uplLoasBtn('1')" :src="url1" /></view>
			<view class="mainC content"><image src="../../static/new/Examples2.png" /><image class="aaa" src="../../static/new/Examples.png" mode=""></image></view>
			<view class="mainD content"><image @click="uplLoasBtn('2')" :src="url2" /></view>
		</view>
		<view class="info">
			<view class="li">
				<view class="title">身份证号码</view>
				<input type="text" v-model="num" placeholder="身份证号" disabled="true" placeholder-style="font-size: 16px;color: #C0C0C0;" />
			</view>
			<view class="li">
				<view class="title">身份证有效期</view>
				<view class="shijian" style="color: #C0C0C0;" v-if="timeText=='有效期限'">{{timeText}}</view>
				<view class="shijian" v-else>{{timeText}}</view>
			</view>
		</view>
		
		<view class="footer">
			<view @click="toSubmit">提交信息</view>
		</view>
	</view>
</template>

<script>
	import store from '../../store/index.js'
	export default {
		data(){
			return {
				num:'',
				url1:'../../static/new/ExamplesA.png',
				url2:'../../static/new/ExamplesB.png',
				timeText:'有效期限',
				front:'',
				side:''
			}
		},
		onLoad() {
			
		},
		methods:{
			uplLoasBtn(type){//类型 1 身份证正面 2 身份证反面
				let _this=  this
				uni.chooseImage({
					count: 1,
					sizeType: 'original',
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						
						uni.showLoading({
							title: '上传中...'
						})
						
						uni.uploadFile({
							url: this.$net.base+'/upload/idcard',
							filePath: tempFilePaths[0],
							name: 'file',
							formData:{type:type},
							success: (uploadFileRes) => {
								uni.hideLoading()
								let arr = JSON.parse(uploadFileRes.data)
								if(arr.code==200){
									if(type==1){
										_this.front = arr.data
										_this.num = arr.data.num
										_this.url1 = tempFilePaths[0]
									}else{
										_this.side = arr.data
										_this.timeText = arr.data.start_date + '~' + arr.data.end_date
										_this.url2 = tempFilePaths[0]
									}
								}else{
									uni.showToast({
										title: '身份证识别失败',
										duration: 2000,
										icon: "none"
									});
								}
							},
							fail: (response) => {
								uni.hideLoading()
							}
						});
					}
				});
			},
			toSubmit(){
				if(this.front==''){
					uni.showToast({
					    title: '请上传身份证正面照',
					    duration: 2000,
						icon:'none'
					});
					return
				}
				if(this.side==''){
					uni.showToast({
					    title: '请上传身份证反面照',
					    duration: 2000,
						icon:'none'
					});
					return
				}
				this.$net.req('/user/idcard', {
					"data": {
						front:this.front,
						side:this.side
					}
				}, false).then(res => {
					if(res.code==200){
						uni.showToast({
						    title: '实名认证成功',
						    duration: 2000,
							icon:'none'
						});
						this.getUser_info()
					}
				})
			},
			getUser_info(){
				this.$net.req('/user/getMine', {}, false).then(res => {
					if(res.code==200){
						store.commit('setUser', res.data);
						uni.navigateBack({
							
						})
					}
				})
			},
		}
	}
</script>

<style>
	page{
		width: 100%;
		height: 100%;
		background-color: #F6F6F6;
	}
</style>
<style scoped lang="scss">
	.wrap{
		width: 100%;
		padding: 20px 16px 0;
		box-sizing: border-box;
		background-color: #FFFFFF;
		position: relative;
		.titles{
			font-size: 16px;
			font-family: HarmonyOS_Sans_SC;
			color: #101010;
			padding-bottom: 16px;
			width: 100%;
			border-bottom: 1px solid rgba(0, 0, 0, 0.06);
		}
		.imgMain{
			width: 100%;
			margin-top: 3px;
			display: flex;
			flex-wrap: wrap;
			align-items: center;
			padding-bottom: 24px;
			.content{
				width: 47%;
				height: 102px;
				background: #F6F6F6;
				border-radius: 4px;
				margin-left: 15px;
				margin-top: 20px;
				padding: 6px;
				box-sizing: border-box;
				&:nth-child(2n+1){
					margin-left: 0;
				}
				image{
					width: 100%;
					height: 100%;
				}
			}
			.mainA{
				position: relative;
				.aaa{
					width: 40px;
					height: 40px;
					position: absolute;
					top: 0;
					right: 0;
				}
			}
			.mainC{
				position: relative;
				.aaa{
					width: 40px;
					height: 40px;
					position: absolute;
					top: 0;
					right: 0;
				}
			}
		}
		.info{
			width: 100%;
			.li{
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 15px 0;
				border-top: 1px solid rgba(0, 0, 0, 0.06);
				.title{
					font-size: 16px;
					font-family: HarmonyOS_Sans_SC;
					color: #101010;
				}
				input{
					text-align: right;
				}
				.shijian{
					display: flex;
					align-items: center;
				
						font-size: 16px;
						font-family: HarmonyOS_Sans_SC;
						color: #101010;
					
				}
			}
		}
		.footer{
			width: 100%;
			height: 80px;
			background: #FFFFFF;
			box-shadow: 0px -6px 10px 0px rgba(0, 0, 0, 0.03);
			// border-radius: 16px 16px 0px 0px;
			position: fixed;
			bottom: 0;
			left: 0;
			padding: 16px 12px;
			box-sizing: border-box;
			view{
				width: 100%;
				height: 48px;
				background: #DFC791;
				border-radius: 8px;
				// border: 2px solid #2F2E3B;
				font-size: 16px;
				font-family: SourceHanSansCN-Medium, SourceHanSansCN;
				font-weight: 500;
				color: #2F2E3B;
				line-height: 48px;
				text-align: center;
			}
		}
	}
</style>
